//
//  SellRankDetailViewController.m
//  A段项目
//
//  Created by cmcmhjr123 on 15/7/15.
//  Copyright (c) 2015年 dlios. All rights reserved.
//

#import "SellRankDetailViewController.h"
#import "BaseHeader.h"
#import "SANetWorkingTask.h"
#import "DataBaseHandler.h"
#import "modelNew.h"
#import "DataBaseHandler.h"



@interface SellRankDetailViewController ()

@property (nonatomic, copy)NSString *wensite1;
@property (nonatomic, assign)NSInteger i;

@end

@implementation SellRankDetailViewController
- (void)dealloc
{
    [super dealloc];
    
}

-(instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationController.navigationBar.translucent = NO;
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"back.png"] style:UIBarButtonItemStyleDone target:self action:@selector(aaa:)];
    self.navigationItem.title = self.name;
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"c.png"] style:UIBarButtonItemStyleDone target:self action:@selector(bbb:)];
    
    
    NSString *web = [NSString stringWithFormat:@"http://api.ycapp.yiche.com/car/GetSerialInfo?csid=%@&tracker=172_ycapp",self.website];
    
    [SANetWorkingTask request:web parmater:nil block:^(NSDictionary *result) {
        NSDictionary *bigdic = [result objectForKey:@"data"];
        self.wensite1 = [bigdic objectForKey:@"shareUrl"];
        
        webview = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeidth)];
        NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:self.wensite1]];
        [webview loadRequest:request];
        [self.view addSubview:webview];
        
    }];
}


- (void)bbb:(id)sender
{
    
    
    if (self.i == 0) {
        DataBaseHandler *data = [DataBaseHandler shareInstance];
        modelNew *modelCollect = [[modelNew alloc] init];
        modelCollect.serialId = self.website;
        modelCollect.serialName = self.name;
        modelCollect.Picture = self.pic;
        
        [data createTableWithString:@"collect"];
        [data insertmodel:modelCollect str:@"collect"];
        UIAlertView *alvi = [[UIAlertView alloc]initWithTitle:@"提示" message:@"收藏成功" delegate:self cancelButtonTitle:@"返回" otherButtonTitles:nil, nil];
        [alvi show];

        self.i = 1;
    }else if (self.i == 1) {
//        DataBaseHandler *dbHanler = [DataBaseHandler shareInstance];
//        [dbHanler deleteWithModel:self.buttonCollect.model tablename:@"collect"];
        
        UIAlertView *alvi = [[UIAlertView alloc]initWithTitle:@"提示" message:@"已收藏" delegate:self cancelButtonTitle:@"返回" otherButtonTitles:nil, nil];
        [alvi show];
//        self.i = 0;
    }
    DataBaseHandler *data = [DataBaseHandler shareInstance];
    modelNew *modelCollect = [[modelNew alloc] init];
    modelCollect.serialId = self.website;
    modelCollect.serialName = self.name;
    modelCollect.Picture = self.pic;
    
    [data createTableWithString:@"collect"];
    [data insertmodel:modelCollect str:@"collect"];
    
    
}



- (void)aaa:(id)sender
{
    
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
